SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[HistorySelectMaxDate]
	@UserId INT
AS
BEGIN
	SELECT MAX(DateCreated)
	FROM HistoryRecord
	WHERE DELETED = 0 
		AND ((@UserId > 0 AND UserId = @UserId) OR (@UserId = 0))
END
GO
